'''
Author: Simon
Date: 2022-02-02 23:37:28
LastEditTime: 2022-02-03 00:23:54
LastEditors: Please set LastEditors
Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
FilePath: /SimonBackend/SimondeAPI/weiboCrawler.py
'''
import requests
import random
import json

def getHotNews():
    header_list = ['Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36',
               'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36',
               'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36'
               ]
    header_index = random.randint(0, len(header_list) - 1)
    header = {
        'User-Agent': header_list[header_index],
        'Cookie': 'user_locale=zh-CN; oschina_new_user=false; sensorsdata2015jssdkchannel=%7B%22prop%22%3A%7B%22_sa_channel_landing_url%22%3A%22%22%7D%7D; remote_way=http; close_wechat_tour=true; slide_id=9; project_pr_sort=closed_at+desc; tz=Asia%2FShanghai; Hm_lvt_24f17767262929947cc3631f99bfd274=1643166001,1643166049,1643168055,1643289752; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%227642266%22%2C%22first_id%22%3A%2217ba5f486a2591-0ae81d507ba0e3-35667c03-1296000-17ba5f486a3639%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%7D%2C%22%24device_id%22%3A%2217ba5f486a2591-0ae81d507ba0e3-35667c03-1296000-17ba5f486a3639%22%7D; gitee_user=true; Hm_lpvt_24f17767262929947cc3631f99bfd274=1643546290; gitee-session-n=QUpRa3hOeFpxc0M4Mm5rRFJmejR5NlUvcTNMUWNTLzl6KzlyZkZheHJHYmpJYXVTVTNlUEgreFozNmx2c3ZSby9PZS8vQjVwdlkyeVFWelNULzFhUEdqQ25QV0ZFSGZvbGp0L0dmdldKblkzUnVqQTk4MjVnMFlvcCtuV0xJN0wzelN0RDMyNWRoWTNYVllXNTBnNU5sZnltU1ZiQjRwUTBFQjVNRnFWZ2dSZlhObVJTTjRCcmdweERsV3NtWlp4cmI2dVhma2FNQUFGWVFMSG5pakxIK0RqQlI2M2paTjNTaGtXWE9TWHhZNjNOdmhJaFhlTk1NN3ZnMGwxUTZjNVc3Z1FKeFMwNUkveXYwanZCUFdBUmxzKzd6eldibnBibFN1TjBDRWxaZ2UzVWhTVThNWmwvQzFsNjIyeHJkRU11bkRLSTZvS25xcVNRRWR6SFMzVEtuZkpZUjhsQmtIZ1pLQm05TkRRaGI0PS0tam5BV1kzM1Fyc3A3cEdIMVVncnVrZz09--8f1005e1fa8ff1a9196ff1536a34925d614f4146'
    }
    # get information
    url = "https://weibo.com/ajax/feed/hottimeline?since_id=0&refresh=0&group_id=102803&containerid=102803&extparam=discover%7Cnew_feed&max_id=0&count=10"
    json_get = requests.get(url, headers=header , verify=False).text
    result_json = json.loads(json_get)
    result = result_json["statuses"]
    # print(result)
    return result


if __name__ == "__main__":
    getHotNews()